-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
buffer: use fast API for writing one-byte strings #54311
buffer: use fast API for writing one-byte strings #54311
Conversation
ronag
commented
Aug 10, 2024
•
edited
Loading
edited
Probably because the benchmark has a flaw, and the input is not a one byte string. I recommend reading this amazing blog post: https://iliazeus.github.io/articles/js-string-optimizations-en/ |
@anonrig still only minimal difference: buffers/buffer-write-string.js n=1000000 len=1 9.21 % ±12.42% ±17.25% ±24.00%
buffers/buffer-write-string.js n=1000000 len=16 * 5.12 % ±4.58% ±6.53% ±9.52%
buffers/buffer-write-string.js n=1000000 len=32 2.87 % ±8.49% ±12.18% ±17.88%
buffers/buffer-write-string.js n=1000000 len=8 ** 8.27 % ±5.40% ±7.68% ±11.10% |
Can you add a printf to fast api function and make sure that it runs? I've had several occasions that I couldn't trigger fast path for super simple calls. |
@anonrig You are right. It's never called and I have no idea why. Do you know anyone that might know more? |
Ah, it's because buffer is this and not the first arg. Do you know if fast API works with this args? |
The first arg (receiver) is the this arg. |
Tried with no this and still no success... seems like a dead end for me |
de22cf8
to
63e7cda
Compare
This works for me and the fast api path is hit starting around 1e4 iterations in the benchmark:
|
Got it to work! buffers/buffer-write-string.js n=1000000 str='a' *** 306.67 % ±7.42% ±10.17% ±13.87%
buffers/buffer-write-string.js n=1000000 str='aa' *** 289.45 % ±3.26% ±4.59% ±6.55%
buffers/buffer-write-string.js n=1000000 str='aaaa' *** 271.79 % ±12.09% ±16.96% ±24.00% looks promising |
f3259aa
to
d1eb51b
Compare
9c98f8f
to
2596951
Compare
2596951
to
6594e2e
Compare
Landed in ccf05ef |
Access violation occurred in FastWriteString function, causing the process to crash and exit. @ronag |
This comment was marked as outdated.
This comment was marked as outdated.
@ShenHongFei Thanks for reporting! Fix is ready. |
I tried applying the patch https://github.com/nodejs/node/pull/54391/files and the problem was solved. Thank you. |
Refs: #54311 (comment) PR-URL: #54391 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]>
PR-URL: #54310 PR-URL: #54311 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Refs: #54311 (comment) PR-URL: #54391 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]>
Notable changes: buffer: * use fast API for writing one-byte strings (Robert Nagy) #54311 * optimize createFromString (Robert Nagy) #54324 * use native copy impl (Robert Nagy) #54087 inspector: * (SEMVER-MINOR) support `Network.loadingFailed` event (Kohei Ueno) #54246 lib: * (SEMVER-MINOR) rewrite AsyncLocalStorage without async_hooks (Stephen Belanger) #48528 module: * (SEMVER-MINOR) unflag detect-module (Geoffrey Booth) #53619 PR-URL: TODO
Notable changes: buffer: * use fast API for writing one-byte strings (Robert Nagy) #54311 * optimize createFromString (Robert Nagy) #54324 * use native copy impl (Robert Nagy) #54087 inspector: * (SEMVER-MINOR) support `Network.loadingFailed` event (Kohei Ueno) #54246 lib: * (SEMVER-MINOR) rewrite AsyncLocalStorage without async_hooks (Stephen Belanger) #48528 module: * (SEMVER-MINOR) unflag detect-module (Geoffrey Booth) #53619 PR-URL: #54452
Notable changes: buffer: * use fast API for writing one-byte strings (Robert Nagy) #54311 * optimize createFromString (Robert Nagy) #54324 * use native copy impl (Robert Nagy) #54087 inspector: * (SEMVER-MINOR) support `Network.loadingFailed` event (Kohei Ueno) #54246 lib: * (SEMVER-MINOR) rewrite AsyncLocalStorage without async_hooks (Stephen Belanger) #48528 module: * (SEMVER-MINOR) add --experimental-transform-types flag (Marco Ippolito) #54283 * (SEMVER-MINOR) unflag detect-module (Geoffrey Booth) #53619 PR-URL: #54452
PR-URL: #54310 PR-URL: #54311 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Refs: #54311 (comment) PR-URL: #54391 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]>
Notable changes: buffer: * use fast API for writing one-byte strings (Robert Nagy) #54311 * optimize createFromString (Robert Nagy) #54324 * use native copy impl (Robert Nagy) #54087 inspector: * (SEMVER-MINOR) support `Network.loadingFailed` event (Kohei Ueno) #54246 lib: * (SEMVER-MINOR) rewrite AsyncLocalStorage without async_hooks (Stephen Belanger) #48528 module: * (SEMVER-MINOR) add --experimental-transform-types flag (Marco Ippolito) #54283 * (SEMVER-MINOR) unflag detect-module (Geoffrey Booth) #53619 PR-URL: #54452
Notable changes: buffer: * use fast API for writing one-byte strings (Robert Nagy) #54311 * optimize createFromString (Robert Nagy) #54324 * use native copy impl (Robert Nagy) #54087 inspector: * (SEMVER-MINOR) support `Network.loadingFailed` event (Kohei Ueno) #54246 lib: * (SEMVER-MINOR) rewrite AsyncLocalStorage without async_hooks (Stephen Belanger) #48528 module: * (SEMVER-MINOR) add --experimental-transform-types flag (Marco Ippolito) #54283 * (SEMVER-MINOR) unflag detect-module (Geoffrey Booth) #53619 PR-URL: #54452